package object;

/**
 * @author: Galen
 * @description: 静态方法
 */
public class StaticCode {
    public static String str1 = "Hello";

    public static int count = 0;
    {
        count++;
        System.out.println("非静态代码块 count=" + count);
    }
    static {
        count++;
        System.out.println("静态代码块1 count=" + count);
    }
    static {
        count++;
        System.out.println("静态代码块2 count=" + count);
    }


    public static void main(String[] args) {
        String str2 = "World";

        // 直接访问 str1
        String accessVar1 = str1 + str2;
        System.out.println(accessVar1);

        // 通过类名访问 str1
        String accessVar2 = StaticCode.str1 + str2;
        System.out.println(accessVar2);

        // 通过对象访问
        StaticCode stcClass = new StaticCode();
        String accessVar3 = stcClass.str1 + str2;
        System.out.println(accessVar3);


        System.out.println("*************** StaticCode1 执行 ***************");
        StaticCode sct1 = new StaticCode();
        System.out.println("*************** StaticCode2 执行 ***************");
        StaticCode sct2 = new StaticCode();
    }

}
